import App from './App'
import store from './store'
import plugin from './js_sdk/uni-admin/plugin'
import messages from './i18n/index.js'

import clone from './js_sdk/clone/clone.js'
import * as XLSX from './js_sdk/xlsx/dist/xlsx.full.min.js'
import chooseAndUploadImage from '@/js_sdk/tencentcloud-plugin-cos/choose-and-upload-image.js';
import chooseAndUploadVideo from '@/js_sdk/tencentcloud-plugin-cos/choose-and-upload-video.js';
import getFileAccessUrl from '@/js_sdk/tencentcloud-plugin-cos/get-file-access-url.js';
import {
	v4 as uuidv4
} from 'uuid';
import Antd from 'ant-design-vue';
import 'ant-design-vue/dist/antd.css';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';


const lang = uni.getLocale()
// #ifndef VUE3
import Vue from 'vue'
import VueI18n from 'vue-i18n'
Vue.config.productionTip = false

Vue.prototype.$XLSX = XLSX
Vue.prototype.$uuid = uuidv4
Vue.prototype.$cloneObject = clone
Vue.prototype.$cdn = 'https://blacks-1311500613.cos.ap-guangzhou.myqcloud.com/'
Vue.prototype.topage = function(url, params) {

	if (params) {
		let queryString = Object.keys(params).map((key) => {
			return encodeURIComponent(key) + '=' + encodeURIComponent(params[key])
		}).join('&');
		uni.navigateTo({
			url: `${url}?${queryString}`
		})
	}
	uni.navigateTo({
		url: `${url}`
	})

}
Vue.prototype.$uploadImg = async function(callBack) {
	try {
		const key = await chooseAndUploadImage(); // 返回的key即上传到COS的图片文件名（不包含域名部分，一般用来提交给后台接口保存到数据库）
		const url = this.$cdn + key // 返回的url即前面上传到COS的图片的访问地址（包含临时签名）
		uni.showToast({
			title: "上传成功",
			duration: 1500,
		})
		callBack(url)
		//inser(url,'aa',url)
	} catch (error) {
		console.log(error);
	}
}
Vue.prototype.$uploadVideo = async function(callBack) {
	try {
		const key = await chooseAndUploadVideo(); // 返回的key即上传到COS的图片文件名（不包含域名部分，一般用来提交给后台接口保存到数据库）
		const url = this.$cdn + key // 返回的url即前面上传到COS的图片的访问地址（包含临时签名）
		uni.showToast({
			title: "上传成功",
			duration: 1500,
		})
		callBack(url)
		//inser(url,'aa',url)
	} catch (error) {
		console.log(error);
	}
}
Vue.use(VueI18n)
Vue.use(ElementUI)
Vue.use(Antd)
// 通过选项创建 VueI18n 实例
const i18n = new VueI18n({
	locale: lang, // 设置地区
	messages, // 设置地区信息
})
Vue.use(plugin)
App.mpType = 'app'
const app = new Vue({
	i18n,
	store,
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import {
	createI18n
} from 'vue-i18n'
export function createApp() {
	const app = createSSRApp(App)
	const i18n = createI18n({
		locale: lang,
		messages
	})
	app.use(i18n)
	app.use(plugin)
	app.use(store)
	return {
		app
	}
}
// #endif
